﻿using System;
using System.Windows.Forms;

namespace TAProject.UI.Service.Price
{
    public partial class FormDoublePrice : FormTemplate
    {
        private readonly Form _parentForm;

        public decimal? PriceAdult { private set; get; }
        public decimal? PriceChild { private set; get; }

        public FormDoublePrice(Form parentForm)
            : base(parentForm)
        {
            InitializeComponent();

            _parentForm = parentForm;
            _parentForm.Enabled = false;
        }

        public FormDoublePrice(Form parentForm, decimal priceAdult, decimal priceChild) : this(parentForm)
        {
            textBoxPriceOne.Text = priceAdult.ToString();
            textBoxPriceTwo.Text = priceChild.ToString();
        }

        private void ButtonSubmitClick(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(textBoxPriceOne.Text) && !string.IsNullOrEmpty(textBoxPriceTwo.Text))
            {
                try
                {
                    PriceAdult = decimal.Parse(textBoxPriceOne.Text.Replace(".", ","));
                    PriceChild = decimal.Parse(textBoxPriceTwo.Text.Replace(".", ","));
                    FormClose();
                }
                catch (Exception)
                {
                    MessageBox.Show("Данные введены некорректно.");
                }
            }
            else
                MessageBox.Show("Не все поля заполнены.");
        }

        private void FormClose()
        {
            _parentForm.Enabled = true;
            Close();
        }

        private void ButtonCancelClick(object sender, EventArgs e)
        {
            PriceAdult = null;
            PriceChild = null;
            FormClose();
        }
    }
}